package com.example.homeworkmutualevaluation.Service;

import com.example.homeworkmutualevaluation.Dao.TeacherDao;
import com.example.homeworkmutualevaluation.Entity.Teacher;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.util.List;

@Service
public class TeacherService {
    @Resource
    private TeacherDao teacherDao;
    public boolean exist(String phone) {
        return teacherDao.findByPhone(phone) != null;
    }
    public Teacher findByPhone(String phone) {
        return teacherDao.findByPhone(phone);
    }
    public Teacher find(String phone, String password) {
        return teacherDao.find(phone, password);
    }
    public boolean register(String phone, String password) {
        return teacherDao.insert(phone, password) > 0;
    }
    public boolean changePassword(String phone, String oldPassword, String newPassword) {
        return teacherDao.updatePassword(phone, oldPassword, newPassword) > 0;
    }
    public boolean changePasswordByAdmin(String phone, String password) {
        return teacherDao.updateByAdmin(phone, password) > 0;
    }
    public List<Teacher> findAll() {
        return teacherDao.findAllSorted();
    }
    public boolean updateInfo(String phone, String name, String sex, Date birthday) {
        return teacherDao.updateInfo(phone, name, sex, birthday) > 0;
    }
    public boolean delete(String phone) {
        return teacherDao.delete(phone) > 0;
    }
    public List<Teacher> findAllByCno(String cno) {
        return teacherDao.findAllByCno(cno);
    }
}
